package cn.xmkeshe.dao;

import cn.xmkeshe.model.OrderDe;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface IOrderDeDao {

  @Insert("insert into orderDe(orid,cuid,iid,title,number,line,orderdate,status,aaccount,caccount)VALUES(#{orid},#{cuid},#{iid},#{title},#{number},#{line},#{orderdate},#{status},#{aaccount},#{caccount})")
  public boolean doCreate(OrderDe orderDe);

  //  分页查询
  @Select("select orid,cuid,iid,title,number,line,orderdate,status from orderDe where status=1 LIMIT #{start},#{lineSize}")
  public List<OrderDe> findAllSplit(Map<String,Object> params);

  //  统计数量
  @Select("select COUNT(orid) from orderDe where status=1")
  public Integer getAllCount();

//  修改订单状态
  @Update("update orderDe set lid=#{lid},price=#{price},delivery=#{delivery},status=#{status} WHERE orid=#{orid}")
  public boolean doUpdateByStatus(OrderDe orderDe);

//  管理员查询已审核订单
  @Select("select o.orid,o.cuid,o.iid,o.title,o.number,o.line,o.orderdate,o.status,l.start,l.end FROM orderDe o join line l WHERE o.status=2 AND o.lid=l.lid LIMIT #{start},#{lineSize}")
  public List<OrderDe> findAllSplitByStatus(Map<String, Object> params);

  @Select("SELECT COUNT(o.orid) FROM orderDe o join line l WHERE o.status=2 AND o.lid=l.lid")
  public Integer getAllCountByStatus();

//  修改已审核订单状态
  @Update("update orderDe set status=3 WHERE orid=#{orid}")
  public boolean doUpdateByStatusa(String orid);

//  查询已完结订单
  @Select("SELECT o.orid,o.cuid,o.iid,o.title,o.number,o.line,o.orderdate,o.status,l.start,l.end FROM orderDe o join line l WHERE o.status=3 AND o.lid=l.lid LIMIT #{start},#{lineSize}")
  public List<OrderDe> findAllSplitByStatus1(Map<String, Object> params);

  @Select("SELECT COUNT(o.orid) FROM orderDe o join line l WHERE o.status=3 AND o.lid=l.lid")
  public Integer getAllCountByStatus1();

  @Select("SELECT orid,title,number,line,orderdate,status,delivery,price,comment FROM orderDe WHERE cuid=#{cuid}")
  public List<OrderDe> findAll(String cuid);

//  订单评价
  @Update("UPDATE orderde set comment=#{comment} WHERE orid = #{orid}")
  public boolean comment(OrderDe orderDe);

////  客户-查看未对账的订单
  @Select("select * from orderde LIMIT #{start},#{lineSize}")
  public List<OrderDe> findCAccount(Map<String, Object> params);

  //  统计数量
  @Select("select COUNT(orid) from orderDe")
  public Integer getCount();

//  修改司机对账
  @Update("UPDATE orderde set aaccount = 1,atime = #{atime} where orid = #{orid}")
  public boolean editAaccount(OrderDe orderDe);

//  修改客户对账
  @Update("UPDATE orderde set caccount = 1,ctime = #{ctime} where orid = #{orid}")
  public boolean editCaccount(OrderDe orderDe);

//  通过订单号查询订单
  @Select("select * from orderde where orid like #{orid} LIMIT #{currentPage},#{lineSize}")
  public List<OrderDe> findByOrid(@Param("currentPage") int currentPage, @Param("lineSize") int lineSize,@Param("orid") String orid);
}
